#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int a[] = {1, 2, 4, 8, 16, 23, 46, 29, 58, 116, 223, 446, 289, 578, 1156, 1223, 2446, 2489, 4789, 5789, 11578, 12356, 12247, 24449};
	int b[] = {48889, 77789, 155578, 111356, 122227, 244445};
	if(n < 25)
	{
		printf("%d", a[n-1]);
	}
	else
	{
		n -= 25;
		printf("%d", b[n % 6]);
	}
	return 0;
}
